﻿var app = angular.module("app", []);
var firebase = 'https://ccamplessons.firebaseio.com/';

app.controller("HomeController", ['$scope', 'PeopleFactory', function ($scope, PeopleFactory){
    $scope.people = PeopleFactory.peopleArray;
    $scope.addPerson = function () {
        var peopleObj = new PeopleFactory.People($scope.name, $scope.age);
        PeopleFactory.postPeople(peopleObj){
            console.log('in controller');
        }
    }
}]);

app.factory("PeopleFactory", function ($http) {
    var People = function (name, age){
        this.name = name;
        this.age = age;
    }
   
    var peopleArray = [new People("Eddie","55"), new People("Sid","76"), new People("Russell","65")];
    
    var getPeople = function (){
        
    };

    var postPeople = function (People){
        $http({
            url: firebase + '.json', 
            method: 'POST',
            data: People
        });
    }
    return {
        People: People,
        peopleArray: peopleArray,
        getPeople: getPeople,
        postPeople: postPeople
    }
});